#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "sequential_list.h"

bool Insert(List L, int X)
{
    if (L->Last + 1 <= MAXSIZE) {
        L->Data[++L->Last] = X;
        return true;
    } else {
        printf("Insert failed !\n");
        return false;
    }
}

bool InsertMany(List L, int elements_count)
{
    int elements_to_insert;
    while (L->Last < elements_count - 1) {
        scanf(" %d", &elements_to_insert);
        if(!Insert(L, elements_to_insert))
            return false;
    }
    return true;
}

void Traverse(List L)
{
    printf("**************** Traverse ****************\n");
    for (int i = 0; i <= L->Last; i++)
        printf("%d ", L->Data[i]);
    printf("\n");
}

List DeleteBetween(List L, int min, int max)
{
    Position p = 0;                                         // The far left position to arrange the elements
    int new_last = L->Last;
    for (int i = 0; i <= L->Last; i++)
    {
        if ((L->Data[i] > min) && (L->Data[i] < max))
            new_last--;
        else
            L->Data[p++] = L->Data[i];
    }
    L->Last = new_last;
    return L;
}
